package nowcode;

import java.util.LinkedList;
import java.util.Queue;

public class FirstAppearingOnceSolution {

    char[] chs = new char[128];

    Queue<Character> queue = new LinkedList<>();

    char minChar = '#';

    //Insert one char from stringstream
    public void Insert(char ch) {
        chs[ch]++;
        queue.add(ch);
        while (!queue.isEmpty() && chs[queue.peek()] > 1) {
            queue.poll();
        }
    }

    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce() {
        if (queue.isEmpty()) {
            return minChar;
        }
        return queue.peek();
    }

}
